<template>
  <div id="rights_container">
    <!-- 卡片区 -->
    <el-card>
      <el-table
        :data="rightsList"
        border
        :row-class-name="tabRowClassName"
        :header-cell-style="getRowClass"
      >
        <el-table-column type="index" align="center"></el-table-column>
        <el-table-column label="权限名称" prop="authName"></el-table-column>
        <el-table-column label="路径" prop="path"></el-table-column>
        <el-table-column label="权限等级">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level === '0'" type="success">一级</el-tag>
            <el-tag v-else-if="scope.row.level === '1'" type="info">二级</el-tag>
            <el-tag v-else type="danger">三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 权限列表
      rightsList: []
    }
  },
  created() {
    // 获取所有的权限
    this.getRightsList()
  },
  methods: {
    // 为所有的 table表头 设置背景颜色
    getRowClass({ rowIndex }) {
      // console.log(rowIndex)
      if (rowIndex == 0) {
        return 'background:RGB(238,239,246)'
      }
    },
    //在methods总通过方法计算返回对应class样式
    tabRowClassName({ rowIndex }) {
      let index = rowIndex + 1
      if (index % 2 == 0) {
        return 'warning-row'
      } else {
        return ''
      }
    },
    // 获取权限列表
    async getRightsList() {
      const { data } = await this.$axios.get('rights/list')
      if (data.meta.status !== 200) {
        return this.$message.error('获取权限列表失败！')
      }

      this.rightsList = data.data
      // console.log(this.rightsList)
    }
  }
}
</script>

<style lang="css" scoped>
#rights_container{
  width: 100%;
}
</style>